<html>
<head>
    <script type="text/javascript">
        var ctx = "${pageContext.request.contextPath}";
    </script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=MYRycSj3ZK1WZdLYEtzi2BDG"></script>
    <%--
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=8gjo01dtzYDldvXPr7nsMIPK"></script>
    --%>
    <title>Hello, World</title>
    <style type="text/css">
        body, html, #allmap {
            width: 100%;
            height: 100%;
            overflow: hidden;
            margin: 0;
        }
    </style>

</head>
<body style="padding:0;">
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
    function request(paramName) {
        //获取URL的字符串
        var sSource = String(window.document.location);
        var sName = paramName;
        var sReturn = "";
        var sQUS = "?";
        var sAMP = "&";
        var sEQ = "=";
        var iPos;

        //获取sSource中的"?"，无则返回 -1
        iPos = sSource.indexOf(sQUS);
        if (iPos == -1)
            return;

        //汲取参数，从iPos letters 置到sSource.length-iPos的 letters 置，
        //若iPos = -1，则：从-1 到 sSource.length+1
        var strQuery = sSource.substr(iPos, sSource.length - iPos);

        // alert(strQuery);
        //先全部转换为小写
        var strLCQuery = strQuery.toLowerCase();
        var strLCName = sName.toLowerCase();

        //从子字符串strLCQuery中查找“?”、参数名，以及“=”，即“?参数名=”
        iPos = strLCQuery.indexOf(sQUS + strLCName + sEQ);
        //alert(iPos);
        //如果不存在
        if (iPos == -1) {
            //继续查找可能的后一个参数，即带“&参数名=”
            iPos = strLCQuery.indexOf(sAMP + strLCName + sEQ);
        }

        //判断是否存在参数
        if (iPos != -1) {
            sReturn = strQuery.substr(iPos + sName.length + 2, strQuery.length - (iPos + sName.length + 2));
            var iPosAMP = sReturn.indexOf(sAMP);
            if (iPosAMP == -1) {
                return sReturn;
            }
            else {
                sReturn = sReturn.substr(0, iPosAMP);
            }
        }
        return sReturn;
    }

    //    var province='<%=request.getParameter("province")%>';
    //    var city='<%=request.getParameter("city")%>';
    //    var district='<%=request.getParameter("district")%>';
    //    var centerAddress='<%=request.getParameter("centerAddress")%>';
    //    var radius='<%=request.getParameter("radius")%>';
    var province = request('province');
    var city = request('city');
    var district = request('district');
    var centerAddress = request('centerAddress');
    var radius = request('radius');
    function Rad(d) {
        return d * Math.PI / 180.0;//经纬度转换成三角函数中度分表形式。
    }

    function GetDistance(lat1, lng1, lat2, lng2) {

        var radLat1 = Rad(lat1);
        var radLat2 = Rad(lat2);
        var a = radLat1 - radLat2;
        var b = Rad(lng1) - Rad(lng2);
        var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
                Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
        s = s * 6378.137;// EARTH_RADIUS;
        s = Math.round(s * 10000) / 10000; //输出为公里
        //s=s.toFixed(4);
        return s;
    }

    var map = new BMap.Map("allmap");
    //    var point = new BMap.Point(116.331398,39.897445);
    //    map.centerAndZoom(point,14);
    map.centerAndZoom("上海", 14);
    var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});// 左上角，添加比例尺
    map.addControl(top_left_control);
    map.enableScrollWheelZoom(true);
    //单击获取点击的经纬度
    var marker = null;
    var circle = null;
    map.addEventListener("click", function (e) {
//        alert(e.point.lng + "," + e.point.lat);
        var point = new BMap.Point(e.point.lng, e.point.lat);
        if (null == marker) {
            marker = new BMap.Marker(point);// 创建标注
            circle = new BMap.Circle(point, radius, {strokeColor: "blue", strokeWeight: 2, strokeOpacity: 0.5}); //创建圆
        } else {
            marker.setPosition(point);
            circle.setCenter(point);
        }
        map.addOverlay(marker);             // 将标注添加到地图中
        map.addOverlay(circle);             // 将标注添加到地图中
        marker.disableDragging();
        parent.Ext.getCmp('addressResponse.lng').setValue(e.point.lng)
        parent.Ext.getCmp('addressResponse.lat').setValue(e.point.lat)
    });
    function theLocation(city) {
//        var city = document.getElementById("cityName").value;
        if (city != "") {
            map.centerAndZoom(city, 14);      // 用城市名设置地图中心点
        }
    }

    theLocation(province + city + district + centerAddress)

</script>